//@author A0086393U
package rightnow.ui.widgets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;

/**
 * Contains the methods and attributes needed to create the error dialog box.
 */
public class ErrorDialogController extends AnchorPane {
	
	private static final Logger LOG = LoggerFactory.getLogger(
			ErrorDialogController.class);
	/* These are components in this section of the UI, and they will be
	 * injected into by FXML automatically.
	 * 
	 * DO NOT CREATE NEW INSTANCES OF THESE! (unless you know what you are doing)
	 */
	@FXML private Label errorMsg;
	@FXML private Button errorButton;
	
	// Called after the FXML file specifying this class as fx:controller is loaded
	@FXML
	public void initialize() {
		LOG.info("Creating error dialog box.");
		
		assert errorMsg != null : "fx:id=\"errorMsg\" was not injected";
		
		LOG.debug("Fxml dependencies successfully injected.");
		LOG.info("Error dialog box successfully created.");
	}
	
	/**
	 * Closes the error dialog box created.
	 */
	@FXML
	protected void closeErrorDialog() {
		errorButton.getScene().getWindow().hide();
	}
	
	/**
	 * Sets the error message in the dialog box created.
	 * @param msg Error message to display.
	 */
	public void setErrorMsg(String msg) {
		errorMsg.setText(msg);
	}
}
